﻿var CheckForm = {
    IsNull: function (str) {
        if (str.length == 0) {
            return false;
        }
        else {
            return true;
        }
    },
    IsPositiveInteger: function (str) {
        //正整数
        var reg = /^(0|([1-9]\d*))$/;
        var bl = reg.test(str);
        return bl;
    },
    isNum: function (str) {
        //数字
        var reg = /^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/;
        var bl = reg.test(str);
        return bl;
    },
    isEmail: function (str) {
        //email
        var reg = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        var bl = reg.test(str);
        return bl;
    },
    isPhone: function (str) {
        //11位手机号
        if (str.length != 11) {
            return false;
        }
        var reg = /(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
        if (!reg.exec(str)) {
            return false;
        }
        return true;
    },
    isDate: function (str) {
        //格式 xxxx-xx-xx or xxxx-x-x
        var bl = true;
        var pattern = /^(19|20)\d{2}-(0?\d|1[012])-(0?\d|[12]\d|3[01])$/;

        if (pattern.test(str)) {
            var str0 = str.split('-')[0];
            var str1 = str.split('-')[1];
            var str2 = str.split('-')[2];
            var dd = new Date(str0, (str1 - 1), str2);
            var temp = dd.toLocaleDateString();
            var newmonth = temp.substring(temp.indexOf('年') + 1, temp.indexOf('月'));
            var index = str1.indexOf("0");
            if (index != 0) {
                if (newmonth != str1) {
                    bl = false;
                }
            }
            else {
                if ("0" + newmonth != str1) {
                    bl = false;
                }
            }
        }
        else {
            bl = false;
        }
        return bl;
    },
    CheckSpecialStr: function (str) {
        var bl = true;
        var arr = new Array("@", "#", "$", "%", "&", "|", "\\", "//");
        i = arr.length;
        j = str.length;
        str = str.trim();
        if (str == "") {
            bl = true;
        } else {
            for (ii = 0; ii < i; ii++) {
                for (jj = 0; jj < j; jj++) {
                    temp1 = str.charAt(jj);
                    temp2 = arr[ii];
                    if (temp1 == temp2) {
                        bl = false;
                    }
                }
            }
        }
        return bl;
    }
};
